﻿package cgs.server.logging
{
    import cgs.Cache.*;
    import cgs.server.abtesting.*;
    import cgs.server.abtesting.messages.*;
    import cgs.server.logging.actions.*;
    import cgs.server.logging.gamedata.*;
    import cgs.server.logging.messages.*;
    import cgs.server.logging.requests.*;
    import cgs.server.logging.responses.*;
    import com.adobe.serialization.json.*;
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.utils.*;

    public class CGSServer extends Object implements IActionBufferListener, ICGSLoggingServer, IABTestingServer
    {
        private var _logPriorityChangeCallback:Function;
        private var _logFailures:Dictionary;
        private var _totalLogFailures:int;
        private var _waitingMessages:Dictionary;
        private var _dynamicQuestIDMap:Dictionary;
        private var _bufferedMessages:Dictionary;
        private var _openQuests:int = 0;
        private var _lastBufferedMessage:BufferedMessage;
        private var _localQuestID:int = 0;
        private var _questGameID:int = -1;
        private var _actionBufferHandlerClass:Class;
        private var _actionBufferHandler:IActionBufferHandler;
        private var _requestHandlerClass:Class;
        private var _requestHandler:IServerRequestHandler;
        private var _logFailuresEnabled:Boolean = false;
        private var _timer:Timer;
        private var _logFailureTime:int = 30000;
        private var _loggingDisabled:Boolean = false;
        private var _requireTermsService:Boolean = false;
        private var _userAcceptedTOS:Boolean = false;
        private var _serverLoggingPriority:int = 1;
        private var _priorityMap:Dictionary;
        private var _currentResponseVersion:int;
        private var _swfDomain:String;
        private var _gameServerData:GameServerData;
        public static const LOG_ALL_DATA:int = 1;
        public static const LOG_PRIORITY_ACTIONS:int = 2;
        public static const LOG_NO_ACTIONS:int = 4;
        public static const LOG_NO_DATA:int = 6;
        public static const LOG_AND_SAVE_NO_DATA:int = 7;
        private static var _instance:CGSServer;

        public function CGSServer()
        {
            this._requestHandlerClass = ServerRequestHandler;
            this._waitingMessages = new Dictionary();
            this._dynamicQuestIDMap = new Dictionary();
            this._bufferedMessages = new Dictionary();
            this._logFailures = new Dictionary();
            this._actionBufferHandlerClass = DefaultActionBufferHandler;
            this._requestHandler = new this._requestHandlerClass();
            this.setupLogPriorites();
            return;
        }// end function

        private function setupLogPriorites() : void
        {
            if (this._priorityMap == null)
            {
                this._priorityMap = new Dictionary();
            }
            this._priorityMap[CGSServerConstants.ACTION_NO_QUEST] = LOG_PRIORITY_ACTIONS;
            this._priorityMap[CGSServerConstants.DQID_REQUEST] = LOG_NO_ACTIONS;
            this._priorityMap[CGSServerConstants.LEGACY_QUEST_START] = LOG_NO_ACTIONS;
            this._priorityMap[CGSServerConstants.LOAD_GAME_DATA] = LOG_NO_DATA;
            this._priorityMap[CGSServerConstants.LOAD_USER_GAME_DATA] = LOG_NO_DATA;
            this._priorityMap[CGSServerConstants.LOG_FAILURE] = LOG_AND_SAVE_NO_DATA;
            this._priorityMap[CGSServerConstants.PAGELOAD] = LOG_NO_ACTIONS;
            this._priorityMap[CGSServerConstants.QUEST_ACTIONS] = LOG_PRIORITY_ACTIONS;
            this._priorityMap[CGSServerConstants.SAVE_GAME_DATA] = LOG_NO_DATA;
            this._priorityMap[CGSServerConstants.QUEST_START] = LOG_NO_ACTIONS;
            this._priorityMap[CGSServerConstants.SAVE_SCORE] = LOG_NO_DATA;
            this._priorityMap[CGSServerConstants.SCORE_REQUEST] = LOG_NO_DATA;
            this._priorityMap[CGSServerConstants.USER_FEEDBACK] = LOG_NO_DATA;
            this._priorityMap[CGSServerConstants.UUID_REQUEST] = LOG_AND_SAVE_NO_DATA;
            return;
        }// end function

        public function resetSingleton() : void
        {
            _instance = null;
            return;
        }// end function

        public function set logPriorityChangeCallback(param1:Function) : void
        {
            this._logPriorityChangeCallback = param1;
            return;
        }// end function

        public function disableLogging() : void
        {
            this._loggingDisabled = true;
            return;
        }// end function

        public function enableLogging() : void
        {
            this._loggingDisabled = false;
            return;
        }// end function

        public function set requireTermsOfService(param1:Boolean) : void
        {
            this._requireTermsService = param1;
            return;
        }// end function

        public function set termsServiceAccepted(param1:Boolean) : void
        {
            this._userAcceptedTOS = param1;
            return;
        }// end function

        private function loggingDisabled(param1:String = null) : Boolean
        {
            var _loc_2:Boolean = false;
            return this._loggingDisabled || this._requireTermsService && !this._userAcceptedTOS || _loc_2;
        }// end function

        public function set actionBufferHandlerClass(param1:Class) : void
        {
            this._actionBufferHandlerClass = param1;
            return;
        }// end function

        public function set serverRequestHandlerClass(param1:Class) : void
        {
            this._requestHandlerClass = param1;
            return;
        }// end function

        public function set serverRequestHandler(param1:IServerRequestHandler) : void
        {
            this._requestHandler = param1;
            return;
        }// end function

        public function init(param1:CGSServerProps, param2:Boolean = true) : void
        {
            this._gameServerData = param2 ? (GameServerData.instance) : (new GameServerData());
            this._gameServerData.skey = param1.skey;
            this._gameServerData.g_name = param1.gameName;
            this._gameServerData.gid = param1.gameID;
            this._gameServerData.cid = param1.categoryID;
            this._gameServerData.vid = param1.versionID;
            if (!param1.isServerURLValid)
            {
                throw new ArgumentError();
            }
            this._gameServerData.serverURL = param1.isServerURLValid ? (param1.serverURL) : (CGSServerConstants.BASE_URL);
            this._gameServerData.abTestingURL = param1.isABTestingURLValid ? (param1.abTestingURL) : (ABTesterConstants.AB_TEST_URL_DEV);
            this._gameServerData.useDevelopmentServer = param1.useDevServer;
            this._gameServerData.skeyHashVersion = param1.skeyHashVersion;
            if (this._swfDomain != null)
            {
                this._gameServerData.swfDomain = this._swfDomain;
            }
            return;
        }// end function

        public function get serverData() : GameServerData
        {
            return this._gameServerData;
        }// end function

        public function set skey(param1:String) : void
        {
            this._gameServerData.skey = param1;
            return;
        }// end function

        public function set skeyHashVersion(param1:int) : void
        {
            this._gameServerData.skeyHashVersion = param1;
            return;
        }// end function

        public function set gameName(param1:String) : void
        {
            this._gameServerData.g_name = param1;
            return;
        }// end function

        public function set gameID(param1:int) : void
        {
            this._gameServerData.gid = param1;
            return;
        }// end function

        public function set questGameID(param1:int) : void
        {
            this._questGameID = param1;
            return;
        }// end function

        public function set versionID(param1:int) : void
        {
            this._gameServerData.vid = param1;
            return;
        }// end function

        public function set categoryID(param1:int) : void
        {
            this._gameServerData.cid = param1;
            return;
        }// end function

        public function set serverURL(param1:String) : void
        {
            this._gameServerData.serverURL = param1;
            return;
        }// end function

        public function set useDevelopmentServer(param1:Boolean) : void
        {
            this._gameServerData.useDevelopmentServer = param1;
            return;
        }// end function

        public function set abTestingURL(param1:String) : void
        {
            this._gameServerData.abTestingURL = param1;
            return;
        }// end function

        public function set legacyMode(param1:Boolean) : void
        {
            this._gameServerData.legacyMode = param1;
            return;
        }// end function

        public function getServerMessage() : Message
        {
            return new Message(this._gameServerData);
        }// end function

        public function genRequest(param1:String, param2:String, param3:Function = null, param4:Object = null, param5:Object = null, param6 = null, param7:Class = null, param8:String = "text") : void
        {
            var _loc_9:* = new ServerRequest(param2, param3, param4, param5, param6, param7, param8, param1, this._gameServerData);
            new ServerRequest(param2, param3, param4, param5, param6, param7, param8, param1, this._gameServerData).urlType = ServerRequest.GENERAL_URL;
            this._requestHandler.request(_loc_9);
            return;
        }// end function

        public function request(param1:String, param2:Function = null, param3:Object = null, param4:Object = null, param5 = null, param6:Class = null, param7:String = "text") : void
        {
            if (this.loggingDisabled(param1))
            {
                if (param2 != null)
                {
                    if (param5 == null)
                    {
                        this.param2(null, true);
                    }
                    else
                    {
                        this.param2(null, true, param5);
                    }
                }
                return;
            }
            var _loc_8:* = new ServerRequest(param1, param2, param3, param4, param5, param6, param7, null, this._gameServerData);
            this._requestHandler.request(_loc_8);
            return;
        }// end function

        public function abRequest(param1:String, param2:Function = null, param3:Object = null, param4:Object = null, param5 = null, param6:Class = null, param7:String = "TEXT") : void
        {
            if (this.loggingDisabled(param1))
            {
                if (param2 != null)
                {
                    if (param5 == null)
                    {
                        this.param2(null, true);
                    }
                    else
                    {
                        this.param2(null, true, param5);
                    }
                }
                return;
            }
            var _loc_8:* = new ServerRequest(param1, param2, param3, param4, param5, param6, param7, null, this._gameServerData);
            new ServerRequest(param1, param2, param3, param4, param5, param6, param7, null, this._gameServerData).urlType = ServerRequest.AB_TESTING_URL;
            this._requestHandler.request(_loc_8);
            return;
        }// end function

        public function requestUserTestConditions(param1:Function = null) : void
        {
            var _loc_2:* = new CallbackRequest(param1);
            var _loc_3:* = new Message(this._gameServerData);
            _loc_3.injectParams();
            this.abRequest(ABTesterConstants.GET_USER_CONDITIONS, this.handleABTestConditions, _loc_3.messageObject, null, _loc_2);
            return;
        }// end function

        private function handleABTestConditions(param1:String, param2:Boolean, param3:CallbackRequest) : void
        {
            var _loc_4:* = param3.callback;
            var _loc_5:Object = null;
            if (!param2)
            {
                _loc_5 = this.parseResponseData(param1);
            }
            if (param2)
            {
                this.logFailure(ABTesterConstants.GET_USER_CONDITIONS);
            }
            if (_loc_4 != null)
            {
                this._loc_4(_loc_5, param2);
            }
            return;
        }// end function

        public function noUserConditions() : void
        {
            var _loc_1:* = new Message(this._gameServerData);
            _loc_1.injectParams();
            this.abRequest(ABTesterConstants.NO_CONDITION_USER, this.handleNoConditionsResponse, _loc_1.messageObject);
            return;
        }// end function

        private function handleNoConditionsResponse(param1:String, param2:Boolean) : void
        {
            return;
        }// end function

        public function logTestStart(param1:int, param2:int, param3:Object = null, param4:Function = null) : void
        {
            var _loc_5:* = new TestStatusMessage(param1, param2, true, param3, this._gameServerData);
            new TestStatusMessage(param1, param2, true, param3, this._gameServerData).injectParams();
            var _loc_6:* = new CallbackRequest(param4);
            this.abRequest(ABTesterConstants.LOG_TEST_START_END, this.testStartLogged, _loc_5.messageObject, null, _loc_6);
            return;
        }// end function

        private function testStartLogged(param1:String, param2:Boolean, param3:CallbackRequest) : void
        {
            var _loc_4:Object = null;
            var _loc_5:* = param3.callback;
            if (!param2)
            {
                _loc_4 = this.parseResponseData(param1);
                this.updateLoggingLoad(_loc_4);
                param2 = this.didRequestFail(_loc_4);
            }
            if (param2)
            {
                this.logFailure(ABTesterConstants.LOG_TEST_START_END);
            }
            if (_loc_5 != null)
            {
                this._loc_5(_loc_4, param2);
            }
            return;
        }// end function

        public function logTestEnd(param1:int, param2:int, param3:Object = null, param4:Function = null) : void
        {
            var _loc_5:* = new TestStatusMessage(param1, param2, false, param3, this._gameServerData);
            new TestStatusMessage(param1, param2, false, param3, this._gameServerData).injectParams();
            var _loc_6:* = new CallbackRequest(param4);
            this.abRequest(ABTesterConstants.LOG_TEST_START_END, this.testEndLogged, _loc_5.messageObject, null, _loc_6);
            return;
        }// end function

        private function testEndLogged(param1:String, param2:Boolean, param3:CallbackRequest) : void
        {
            var _loc_4:Object = null;
            var _loc_5:* = param3.callback;
            if (!param2)
            {
                _loc_4 = this.parseResponseData(param1);
                this.updateLoggingLoad(_loc_4);
                param2 = this.didRequestFail(_loc_4);
            }
            if (param2)
            {
                this.logFailure(ABTesterConstants.LOG_TEST_START_END);
            }
            if (_loc_5 != null)
            {
                this._loc_5(_loc_4, param2);
            }
            return;
        }// end function

        public function logConditionVariableStart(param1:int, param2:int, param3:int, param4:int, param5:Number = -1, param6:Object = null, param7:Function = null) : void
        {
            var _loc_8:* = new ConditionVariableMessage(param1, param2, param3, param4, true, param5, param6, this._gameServerData);
            new ConditionVariableMessage(param1, param2, param3, param4, true, param5, param6, this._gameServerData).injectParams();
            var _loc_9:* = new CallbackRequest(param7);
            this.abRequest(ABTesterConstants.LOG_CONDITION_RESULTS, this.conditionResultsLogged, _loc_8.messageObject, null, _loc_9);
            return;
        }// end function

        public function logConditionVariableResults(param1:int, param2:int, param3:int, param4:int, param5:Number = -1, param6:Object = null, param7:Function = null) : void
        {
            var _loc_8:* = new ConditionVariableMessage(param1, param2, param3, param4, false, param5, param6, this._gameServerData);
            new ConditionVariableMessage(param1, param2, param3, param4, false, param5, param6, this._gameServerData).injectParams();
            var _loc_9:* = new CallbackRequest(param7);
            this.abRequest(ABTesterConstants.LOG_CONDITION_RESULTS, this.conditionResultsLogged, _loc_8.messageObject, null, _loc_9);
            return;
        }// end function

        private function conditionResultsLogged(param1:String, param2:Boolean, param3:CallbackRequest) : void
        {
            var _loc_4:Object = null;
            var _loc_5:* = param3.callback;
            if (!param2)
            {
                _loc_4 = this.parseResponseData(param1);
                this.updateLoggingLoad(_loc_4);
                param2 = this.didRequestFail(_loc_4);
            }
            if (param2)
            {
                this.logFailure(ABTesterConstants.LOG_CONDITION_RESULTS);
            }
            if (_loc_5 != null)
            {
                this._loc_5(_loc_4, param2);
            }
            return;
        }// end function

        public function get logFailureCount() : int
        {
            return this._totalLogFailures;
        }// end function

        private function startLogFailureTimer() : void
        {
            if (this._timer != null || !this._logFailuresEnabled)
            {
                return;
            }
            this._timer = new Timer(this._logFailureTime);
            this._timer.addEventListener(TimerEvent.TIMER, this.handleSendLogFailures);
            this._timer.start();
            return;
        }// end function

        private function stopLogFailureTimer() : void
        {
            if (this._timer == null)
            {
                return;
            }
            this._timer.stop();
            this._timer.removeEventListener(TimerEvent.TIMER, this.handleSendLogFailures);
            this._timer = null;
            return;
        }// end function

        private function handleSendLogFailures(event:TimerEvent) : void
        {
            if (!this._logFailuresEnabled)
            {
                return;
            }
            this.tryLogRequestFailures();
            return;
        }// end function

        protected function logFailure(param1:String, param2:int = 1, param3:Boolean = false) : void
        {
            if (!this._logFailuresEnabled)
            {
                return;
            }
            var _loc_4:* = this._logFailures[param1];
            if (this._logFailures[param1] == null)
            {
                _loc_4 = new FailureRequest(param1);
                this._logFailures[param1] = _loc_4;
            }
            this.startLogFailureTimer();
            _loc_4.incrementCount(param2);
            if (!param3)
            {
                this._totalLogFailures = this._totalLogFailures + param2;
            }
            return;
        }// end function

        public function tryLogRequestFailures() : void
        {
            var _loc_2:String = null;
            var _loc_3:String = null;
            var _loc_1:FailureRequest = null;
            for (_loc_3 in this._logFailures)
            {
                
                _loc_2 = _loc_3;
                _loc_1 = this._logFailures[_loc_3];
                break;
            }
            if (_loc_1 != null)
            {
                delete this._logFailures[_loc_2];
                this.logRequestFailure(_loc_1, this.handleTryLogFailures);
            }
            else
            {
                this.stopLogFailureTimer();
            }
            return;
        }// end function

        protected function logRequestFailure(param1:FailureRequest, param2:Function = null) : void
        {
            param2 = param2 == null ? (this.handleLogFailure) : (param2);
            var _loc_3:* = new Message(this._gameServerData);
            _loc_3.injectParams();
            this.request(CGSServerConstants.LOG_FAILURE, param2, _loc_3.messageObject, null, param1);
            return;
        }// end function

        protected function logRequestFailures() : void
        {
            var _loc_2:String = null;
            var _loc_3:FailureRequest = null;
            var _loc_1:Array = [];
            for (_loc_2 in this._logFailures)
            {
                
                _loc_1.push(this._logFailures[_loc_2]);
            }
            for each (_loc_3 in _loc_1)
            {
                
                this.logRequestFailure(_loc_3);
            }
            return;
        }// end function

        protected function handleLogFailure(param1:String, param2:Boolean, param3:FailureRequest) : void
        {
            if (param2)
            {
                this.logFailure(param3.method, param3.count, true);
            }
            return;
        }// end function

        protected function handleTryLogFailures(param1:String, param2:Boolean, param3:FailureRequest) : void
        {
            var _loc_5:Object = null;
            var _loc_4:Boolean = false;
            if (!param2)
            {
                _loc_5 = this.parseResponseData(param1);
                _loc_4 = this.didRequestFail(_loc_5);
                this.logRequestFailures();
            }
            if (param2)
            {
                this.logFailure(param3.method, param3.count, true);
            }
            return;
        }// end function

        public function requestUUID(param1:Function, param2:Boolean = false, param3:String = null) : void
        {
            var _loc_7:String = null;
            var _loc_4:Boolean = false;
            if (param3 != null)
            {
                this._gameServerData.uuid = param3;
                if (param2)
                {
                    this.saveUUID(param3);
                }
                _loc_4 = true;
            }
            if (param2)
            {
                _loc_7 = this.loadUUID();
                if (_loc_7 != null)
                {
                    this._gameServerData.uuid = _loc_7;
                    _loc_4 = true;
                }
            }
            if (_loc_4)
            {
                if (param1 != null)
                {
                    this.param1(this._gameServerData.uuid, false);
                }
                return;
            }
            var _loc_5:* = new UUIDRequest(param1, param2);
            var _loc_6:* = new Message(this._gameServerData);
            new Message(this._gameServerData).injectGameParams();
            _loc_6.injectSKEY();
            this.request(CGSServerConstants.UUID_REQUEST, this.handleUUIDLoaded, _loc_6.messageObject, null, _loc_5);
            return;
        }// end function

        private function handleUUIDLoaded(param1:String, param2:Boolean, param3:UUIDRequest) : void
        {
            var urlVars:URLVariables;
            var jsonString:String;
            var decoder:JSONDecoder;
            var uuidObject:Object;
            var cacheUUID:Boolean;
            var callback:Function;
            var vars:* = param1;
            var failed:* = param2;
            var request:* = param3;
            var uuid:String;
            var uuidFailed:Boolean;
            try
            {
                urlVars = new URLVariables(vars);
                jsonString = urlVars.data;
                decoder = new JSONDecoder(jsonString, true);
                uuidObject = decoder.getValue();
                uuid = uuidObject.uid;
                this._gameServerData.uuid = uuid;
            }
            catch (er:Error)
            {
                uuidFailed;
            }
            finally
            {
                cacheUUID = request.cacheUUID;
                if (cacheUUID && !uuidFailed)
                {
                    this.saveUUID(uuid);
                }
                callback = request.callback;
                if (callback != null)
                {
                    this.callback(uuid, failed || uuidFailed);
                }
            }
            return;
        }// end function

        protected function saveUUID(param1:String) : void
        {
            Cache.setSave("cgs_uid", param1);
            return;
        }// end function

        protected function loadUUID() : String
        {
            return Cache.getSave("cgs_uid");
        }// end function

        public function containsUUID() : Boolean
        {
            return Cache.saveExists("cgs_uid");
        }// end function

        public function clearCachedUUID() : void
        {
            Cache.deleteSave("cgs_uid");
            return;
        }// end function

        public function logActionNoQuest(param1:ActionNoQuestMessage, param2:Function = null) : void
        {
            param1.serverData = this._gameServerData;
            param1.injectParams();
            this.request(CGSServerConstants.ACTION_NO_QUEST, this.handleActionNoQuestResponse, param1.messageObject, null, param2);
            return;
        }// end function

        private function handleActionNoQuestResponse(param1:String, param2:Boolean, param3:Function = null) : void
        {
            var _loc_4:Object = null;
            if (!param2)
            {
                _loc_4 = this.parseResponseData(param1);
                this.updateLoggingLoad(_loc_4);
                param2 = this.didRequestFail(_loc_4);
            }
            if (param2)
            {
                this.logFailure(CGSServerConstants.ACTION_NO_QUEST);
            }
            if (param3 != null)
            {
                this.param3(_loc_4, param2);
            }
            return;
        }// end function

        public function logPageLoad(param1:Object = null, param2:Function = null) : void
        {
            var _loc_3:* = new PageloadMessage(param1, this._gameServerData);
            _loc_3.injectParams();
            _loc_3.injectEventID(true);
            this.request(CGSServerConstants.PAGELOAD, this.handlePageLoadResponse, _loc_3.messageObject, null, param2);
            return;
        }// end function

        private function handlePageLoadResponse(param1:String, param2:Boolean, param3:Function = null) : void
        {
            var _loc_4:Object = null;
            if (!param2)
            {
                _loc_4 = this.parseResponseData(param1);
                this.updateLoggingLoad(_loc_4);
                param2 = this.didRequestFail(_loc_4);
            }
            if (param2)
            {
                this.logFailure(CGSServerConstants.PAGELOAD);
            }
            if (param3 != null)
            {
                this.param3(_loc_4, param2);
            }
            return;
        }// end function

        public function submitUserFeedback(param1:UserFeedbackMessage, param2:Function = null) : void
        {
            param1.serverData = this._gameServerData;
            param1.injectParams();
            var _loc_3:* = new CallbackRequest(param2);
            this.request(CGSServerConstants.USER_FEEDBACK, this.handleUserInfoSentMessage, param1.messageObject, null, _loc_3);
            return;
        }// end function

        protected function handleUserInfoSentMessage(param1:String, param2:Boolean, param3:CallbackRequest) : void
        {
            var _loc_4:Object = null;
            var _loc_5:* = param3.callback;
            if (!param2)
            {
                _loc_4 = this.parseResponseData(param1);
                this.updateLoggingLoad(_loc_4);
                param2 = this.didRequestFail(_loc_4);
            }
            if (param2)
            {
                this.logFailure(CGSServerConstants.USER_FEEDBACK);
            }
            if (_loc_5 != null)
            {
                this._loc_5(param1, param2);
            }
            return;
        }// end function

        private function getLocalDQID() : int
        {
            var _loc_1:String = this;
            _loc_1._localQuestID = this._localQuestID + 1;
            return ++this._localQuestID;
        }// end function

        private function get currentLocalDQID() : int
        {
            return this._localQuestID;
        }// end function

        public function get lastLocalDQID() : int
        {
            return this._lastBufferedMessage != null ? (this._lastBufferedMessage.getLocalDQID()) : (-1);
        }// end function

        private function get currentQuestID() : int
        {
            return this._lastBufferedMessage != null ? (this._lastBufferedMessage.getQuestID()) : (0);
        }// end function

        private function get currentDQID() : String
        {
            return this._lastBufferedMessage != null ? (this._lastBufferedMessage.dqid) : ("");
        }// end function

        private function getDQID(param1:int = -1) : String
        {
            var _loc_2:* = param1 < 0 ? (this._lastBufferedMessage) : (this._bufferedMessages[param1]);
            return _loc_2 != null ? (_loc_2.dqid) : (null);
        }// end function

        private function getBufferedMessage(param1:int) : BufferedMessage
        {
            return param1 < 0 ? (this._lastBufferedMessage) : (this._bufferedMessages[param1]);
        }// end function

        public function requestDQID(param1:Function, param2:int = -1) : int
        {
            if (param2 == -1)
            {
                param2 = this.getLocalDQID();
            }
            var _loc_3:* = new DQIDRequest(param2, param1);
            var _loc_4:* = new Message(this._gameServerData);
            new Message(this._gameServerData).injectGameParams();
            _loc_4.injectSKEY();
            this.request(CGSServerConstants.DQID_REQUEST, this.handleDQIDResponse, _loc_4.messageObject, null, _loc_3);
            return param2;
        }// end function

        protected function handleDQIDResponse(param1:String, param2:Boolean, param3:DQIDRequest) : void
        {
            var urlVars:URLVariables;
            var decoder:JSONDecoder;
            var jsonObj:Object;
            var localID:int;
            var data:* = param1;
            var failed:* = param2;
            var dqidRequest:* = param3;
            var callback:* = dqidRequest.callback;
            var dqid:String;
            var dqidFailed:Boolean;
            try
            {
                urlVars = new URLVariables(data);
                decoder = new JSONDecoder(urlVars.data, true);
                jsonObj = decoder.getValue();
                dqid = jsonObj.dqid;
            }
            catch (er:Error)
            {
                dqidFailed;
                dqid;
            }
            finally
            {
                if (!dqidFailed || !failed)
                {
                    localID = dqidRequest.localLevelID;
                    this._dynamicQuestIDMap[localID] = dqid;
                    this.updateBufferMessageDQID(dqid, localID);
                    this.sendQueuedMessages(localID, dqid);
                }
                if (callback != null)
                {
                    this.callback(dqid, failed);
                }
            }
            return;
        }// end function

        private function updateBufferMessageDQID(param1:String, param2:int) : void
        {
            var _loc_3:* = this._bufferedMessages[param2];
            if (_loc_3 == null)
            {
                return;
            }
            if (_loc_3.getLocalDQID() == param2)
            {
                _loc_3.setDQID(param1);
            }
            return;
        }// end function

        protected function sendQueuedMessages(param1:int, param2:String) : void
        {
            var _loc_4:QuestRequest = null;
            var _loc_5:Function = null;
            var _loc_3:* = this._waitingMessages[param1];
            delete this._waitingMessages[param1];
            if (_loc_3 == null)
            {
                return;
            }
            var _loc_6:* = _loc_3.length - 1;
            while (_loc_6 >= 0)
            {
                
                _loc_4 = _loc_3[_loc_6];
                _loc_4.setDQID(param2);
                _loc_5 = _loc_4.requestCallback;
                if (_loc_5 != null)
                {
                    this._loc_5(_loc_4);
                }
                _loc_6 = _loc_6 - 1;
            }
            return;
        }// end function

        public function createQuest(param1:String, param2:int, param3:Function = null) : void
        {
            var _loc_4:* = new CreateQuestRequest(param1, param2);
            new CreateQuestRequest(param1, param2).injectParams();
            var _loc_5:* = new CallbackRequest(param3);
            this.request(CGSServerConstants.CREATE_QUEST, this.handleCreateQuestResponse, _loc_4.messageObject, null, _loc_5);
            return;
        }// end function

        private function handleCreateQuestResponse(param1:String, param2:Boolean, param3:ServerRequest) : void
        {
            var callback:Function;
            var urlVariables:URLVariables;
            var decoder:JSONDecoder;
            var jsonObject:Object;
            var questData:Object;
            var qid:int;
            var data:* = param1;
            var failed:* = param2;
            var request:* = param3;
            callback = request.callback;
            if (failed)
            {
                if (callback != null)
                {
                    this.callback(-1, true);
                }
                this.logFailure(CGSServerConstants.CREATE_QUEST);
            }
            else
            {
                try
                {
                    urlVariables = new URLVariables(data);
                    decoder = new JSONDecoder(urlVariables.data, true);
                    jsonObject = decoder.getValue();
                    questData = jsonObject.rdata;
                    qid = questData.qid;
                    if (callback != null)
                    {
                        this.callback(qid, false);
                    }
                }
                catch (er:Error)
                {
                    if (callback != null)
                    {
                        this.callback(-1, true);
                    }
                }
            }
            return;
        }// end function

        private function createQuestMessageBuffer(param1:int, param2:int, param3:String = null) : BufferedMessage
        {
            this._lastBufferedMessage = new BufferedMessage(this._gameServerData);
            this._lastBufferedMessage.setLocalDQID(param2);
            this._lastBufferedMessage.setQuestID(param1);
            this._lastBufferedMessage.setDQID(param3);
            if (!this._bufferedMessages.hasOwnProperty(param2))
            {
                var _loc_4:String = this;
                var _loc_5:* = this._openQuests + 1;
                _loc_4._openQuests = _loc_5;
            }
            this._bufferedMessages[param2] = this._lastBufferedMessage;
            return this._lastBufferedMessage;
        }// end function

        private function removeQuestMessageBuffer(param1:int = -1) : void
        {
            var _loc_2:BufferedMessage = null;
            if (param1 < 0)
            {
                param1 = this.currentLocalDQID;
            }
            if (this._bufferedMessages.hasOwnProperty(param1))
            {
                var _loc_3:String = this;
                var _loc_4:* = this._openQuests - 1;
                _loc_3._openQuests = _loc_4;
                _loc_2 = this._bufferedMessages[param1];
                delete this._bufferedMessages[param1];
                if (_loc_2 == this._lastBufferedMessage)
                {
                    this._lastBufferedMessage = null;
                    this.updateLastBufferedMessage();
                }
            }
            return;
        }// end function

        private function updateLastBufferedMessage() : void
        {
            var _loc_1:String = null;
            for (_loc_1 in this._bufferedMessages)
            {
                
                this._lastBufferedMessage = this._bufferedMessages[_loc_1];
                break;
            }
            return;
        }// end function

        public function logQuestStartWithDQID(param1:int, param2:String, param3:Object, param4:String = null, param5:int = -1) : int
        {
            var _loc_6:* = param5 < 0 ? (this.getLocalDQID()) : (param5);
            this.createQuestMessageBuffer(param1, _loc_6, param2);
            var _loc_7:* = new QuestMessage(param1, param3, true, param4, param2, this._gameServerData);
            var _loc_8:* = new QuestRequest(null, _loc_7, this.sendQuestMessage, this._questGameID);
            this.sendQuestMessage(_loc_8);
            this.resetActionBufferHandler();
            this.startActionBufferHandler();
            return _loc_6;
        }// end function

        private function sendQuestMessage(param1:QuestRequest) : void
        {
            this.request(CGSServerConstants.QUEST_START, this.handleQuestStartResponse, param1.questMessageObject, null, param1);
            return;
        }// end function

        private function sendLegacyQuestMessage(param1:QuestRequest) : void
        {
            this.request(CGSServerConstants.LEGACY_QUEST_START, this.handleQuestStartResponse, param1.questMessageObject, null, param1);
            return;
        }// end function

        private function handleQuestStartResponse(param1:String, param2:Boolean, param3:QuestRequest) : void
        {
            var _loc_4:* = param3.callback;
            var _loc_5:* = this.parseResponseData(param1);
            if (this.parseResponseData(param1) != null)
            {
                this.updateLoggingLoad(_loc_5);
                param2 = this.didRequestFail(_loc_5);
            }
            else
            {
                param2 = true;
            }
            if (param2)
            {
                this.logFailure(CGSServerConstants.QUEST_START);
            }
            if (_loc_4 != null)
            {
                this._loc_4(param3.getDQID(), param2);
            }
            return;
        }// end function

        public function logQuestStart(param1:int, param2:Object, param3:Function = null, param4:String = null, param5:int = -1) : int
        {
            return this.localLogQuestStart(param1, param2, param3, param4, param5);
        }// end function

        private function localLogQuestStart(param1:int, param2:Object, param3:Function = null, param4:String = null, param5:int = -1, param6:Boolean = false) : int
        {
            var _loc_7:* = new QuestMessage(param1, param2, true, param4, null, this._gameServerData);
            var _loc_8:* = new QuestRequest(param3, _loc_7, param6 ? (this.sendLegacyQuestMessage) : (this.sendQuestMessage), this._questGameID);
            param5 = this.requestDQID(null, param5);
            this.createQuestMessageBuffer(param1, param5);
            this.queueQuestMessage(_loc_8, param5);
            this.resetActionBufferHandler();
            this.startActionBufferHandler();
            return param5;
        }// end function

        public function legacyLogQuestStart(param1:int, param2:Object, param3:Function = null, param4:String = null, param5:int = -1) : int
        {
            return this.localLogQuestStart(param1, param2, param3, param4, param5, true);
        }// end function

        protected function queueQuestMessage(param1:QuestRequest, param2:int = -1) : void
        {
            if (param2 < 0)
            {
                param2 = this._lastBufferedMessage != null ? (this._lastBufferedMessage.getLocalDQID()) : (param2);
            }
            if (this._dynamicQuestIDMap.hasOwnProperty(param2))
            {
                param1.setDQID(this._dynamicQuestIDMap[param2]);
                this.sendQuestMessage(param1);
                return;
            }
            var _loc_3:* = this._waitingMessages[param2];
            if (_loc_3 == null)
            {
                _loc_3 = new Array();
                this._waitingMessages[param2] = _loc_3;
            }
            _loc_3.push(param1);
            return;
        }// end function

        public function logQuestEnd(param1:int, param2:Object, param3:Function = null, param4:int = -1) : void
        {
            var _loc_5:* = new QuestMessage(param1, param2, false, null, null, this._gameServerData);
            var _loc_6:* = new QuestRequest(param3, _loc_5, this.sendQuestMessage, this._questGameID);
            _loc_5.setDQID(this.getDQID(param4));
            this.flushActionsOptions(true, param4);
            instance.resetActionBufferHandler();
            instance.stopActionBufferHandler();
            if (_loc_5.isDQIDValid)
            {
                this.sendQuestMessage(_loc_6);
            }
            else
            {
                this.queueQuestMessage(_loc_6, param4);
            }
            return;
        }// end function

        public function logQuestAction(param1:ClientAction, param2:int = -1, param3:Boolean = false) : void
        {
            var _loc_4:* = this.getBufferedMessage(param2);
            if (param1.isBufferable())
            {
                _loc_4.addAction(param1);
            }
            else
            {
                this.flushActions(param2);
                _loc_4.addAction(param1);
                param3 = true;
            }
            if (param3)
            {
                this.flushActions(param2);
            }
            return;
        }// end function

        public function pauseActionBufferHandler() : void
        {
            if (this._actionBufferHandler == null)
            {
                return;
            }
            this._actionBufferHandler.stop();
            return;
        }// end function

        public function resumeActionBufferHandler() : void
        {
            if (this._actionBufferHandler == null)
            {
                return;
            }
            this._actionBufferHandler.start();
            return;
        }// end function

        private function resetActionBufferHandler() : void
        {
            if (this._actionBufferHandler == null)
            {
                this._actionBufferHandler = new this._actionBufferHandlerClass();
                this._actionBufferHandler.listener = this;
                this._actionBufferHandler.setProperties(CGSServerConstants.bufferFlushIntervalStart, CGSServerConstants.bufferFlushIntervalEnd, CGSServerConstants.bufferFlushRampTime);
            }
            this._actionBufferHandler.reset();
            return;
        }// end function

        private function startActionBufferHandler() : void
        {
            if (this._actionBufferHandler == null)
            {
                this._actionBufferHandler = new this._actionBufferHandlerClass();
                this._actionBufferHandler.listener = this;
                this._actionBufferHandler.setProperties(CGSServerConstants.bufferFlushIntervalStart, CGSServerConstants.bufferFlushIntervalEnd, CGSServerConstants.bufferFlushRampTime);
            }
            this._actionBufferHandler.start();
            return;
        }// end function

        private function stopActionBufferHandler() : void
        {
            if (this._actionBufferHandler == null)
            {
                return;
            }
            this._actionBufferHandler.stop();
            return;
        }// end function

        public function flushActions(param1:int = -1, param2:Function = null) : void
        {
            this.flushActionsOptions(false, param1, param2);
            return;
        }// end function

        private function flushActionsOptions(param1:Boolean, param2:int = -1, param3:Function = null) : void
        {
            if (param2 < 0)
            {
                this.flushAllActions(param1, param3);
            }
            else
            {
                this.flushQuestActionsByID(param1, param2, param3);
            }
            return;
        }// end function

        private function flushAllActions(param1:Boolean, param2:Function = null) : void
        {
            var _loc_3:String = null;
            for (_loc_3 in this._bufferedMessages)
            {
                
                this.flushQuestActions(param1, this._bufferedMessages[_loc_3], param2);
            }
            return;
        }// end function

        private function flushQuestActionsByID(param1:Boolean, param2:int, param3:Function = null) : void
        {
            this.flushQuestActions(param1, this.getBufferedMessage(param2), param3);
            return;
        }// end function

        private function flushQuestActions(param1:Boolean, param2:BufferedMessage, param3:Function = null) : void
        {
            if (param2 == null)
            {
                return;
            }
            if (!param2.isDQIDValid())
            {
                if (this._dynamicQuestIDMap.hasOwnProperty(param2.getLocalDQID()))
                {
                    param2.setDQID(this._dynamicQuestIDMap[param2.getLocalDQID()]);
                }
            }
            if (param1)
            {
                this.removeQuestMessageBuffer(param2.getLocalDQID());
            }
            else if (param2.getActionCount() > 0)
            {
                this.createQuestMessageBuffer(param2.getQuestID(), param2.getLocalDQID(), param2.dqid);
            }
            if (param2.getActionCount() == 0)
            {
                return;
            }
            var _loc_4:* = new QuestRequest(param3, param2, this.sendActionsToServer, this._questGameID);
            if (param2.isDQIDValid())
            {
                this.sendActionsToServer(_loc_4);
            }
            else
            {
                this.queueQuestMessage(_loc_4, param2.getLocalDQID());
            }
            return;
        }// end function

        private function sendActionsToServer(param1:QuestRequest) : void
        {
            this.request(CGSServerConstants.QUEST_ACTIONS, this.handleActionResponse, param1.questMessageObject, null, param1);
            return;
        }// end function

        protected function handleActionResponse(param1:String, param2:Boolean, param3:QuestRequest) : void
        {
            var _loc_4:* = param3.questMessage as BufferedMessage;
            if (param2)
            {
                this.handleFailedActions(_loc_4);
                return;
            }
            var _loc_5:* = this.parseResponseData(param1);
            param2 = this.didRequestFail(_loc_5);
            if (param2)
            {
                this.handleFailedActions(_loc_4);
            }
            this.updateLoggingLoad(_loc_5);
            var _loc_6:* = param3.callback;
            if (param3.callback != null)
            {
                this._loc_6(_loc_5, param2);
            }
            return;
        }// end function

        private function updateLoggingLoad(param1:Object) : void
        {
            var _loc_2:int = 0;
            if (param1 == null)
            {
                return;
            }
            if (param1.hasOwnProperty("tload"))
            {
                _loc_2 = param1.tload;
                if (this._serverLoggingPriority != _loc_2)
                {
                    this._serverLoggingPriority = _loc_2;
                    if (this._logPriorityChangeCallback != null)
                    {
                        this._logPriorityChangeCallback(this._serverLoggingPriority);
                    }
                }
            }
            return;
        }// end function

        private function handleFailedActions(param1:BufferedMessage) : void
        {
            this.logFailure(CGSServerConstants.QUEST_ACTIONS, param1.getActionCount());
            return;
        }// end function

        private function handleFailedRequest(param1:IServerRequest) : void
        {
            return;
        }// end function

        public function logQuestScore(param1:Number, param2:Function = null, param3:int = -1) : void
        {
            var _loc_4:* = new ScoreMessage(param1, this._gameServerData);
            new ScoreMessage(param1, this._gameServerData).setQuestID(this.currentQuestID);
            var _loc_5:* = new QuestRequest(param2, _loc_4, this.sendScoreMessage, this._questGameID);
            var _loc_6:* = this.getBufferedMessage(param3);
            if (this.getBufferedMessage(param3).isDQIDValid())
            {
                _loc_4.setDQID(this.currentDQID);
                this.sendScoreMessage(_loc_5);
            }
            else
            {
                this.queueQuestMessage(_loc_5, _loc_6.getLocalDQID());
            }
            return;
        }// end function

        private function sendScoreMessage(param1:QuestRequest) : void
        {
            this.request(CGSServerConstants.SAVE_SCORE, this.handleSaveScoreResponse, param1.questMessageObject, null, param1);
            return;
        }// end function

        public function logScore(param1:Number, param2:int, param3:Function = null) : void
        {
            var _loc_4:* = new ScoreMessage(param1, this._gameServerData);
            new ScoreMessage(param1, this._gameServerData).setQuestID(param2);
            _loc_4.injectParams();
            var _loc_5:* = new CallbackRequest(param3);
            this.request(CGSServerConstants.SAVE_SCORE, this.handleSaveScoreResponse, _loc_4.messageObject, null, _loc_5);
            return;
        }// end function

        private function handleSaveScoreResponse(param1:String, param2:Boolean, param3:CallbackRequest = null) : void
        {
            var _loc_4:Function = null;
            if (param3 != null)
            {
                _loc_4 = param3.callback;
            }
            var _loc_5:Object = null;
            if (!param2)
            {
                _loc_5 = this.parseResponseData(param1);
                this.updateLoggingLoad(_loc_5);
                param2 = this.didRequestFail(_loc_5);
            }
            if (_loc_4 != null)
            {
                this._loc_4(_loc_5, param2);
            }
            return;
        }// end function

        public function requestScores() : void
        {
            return;
        }// end function

        public function saveGameData(param1:String, param2, param3:Function = null) : void
        {
            var _loc_6:JSONEncoder = null;
            var _loc_4:* = new Message(this._gameServerData);
            new Message(this._gameServerData).addProperty("udata_id", param1);
            if (param2 != null)
            {
                _loc_6 = new JSONEncoder(param2);
                _loc_4.addProperty("data_detail", _loc_6.getString());
            }
            _loc_4.injectParams();
            var _loc_5:* = new GameDataRequest(param3, param1);
            this.request(CGSServerConstants.SAVE_GAME_DATA, this.handleGameDataSaved, _loc_4.messageObject, null, _loc_5);
            return;
        }// end function

        private function handleGameDataSaved(param1:String, param2:Boolean, param3:GameDataRequest) : void
        {
            var _loc_6:Object = null;
            var _loc_4:* = param3.callback;
            var _loc_5:* = param3.dataID;
            if (!param2)
            {
                _loc_6 = this.parseResponseData(param1);
                this.updateLoggingLoad(_loc_6);
                param2 = this.didRequestFail(_loc_6);
            }
            if (_loc_4 != null)
            {
                this._loc_4(_loc_5, param2);
            }
            return;
        }// end function

        public function loadGameData(param1:Function) : void
        {
            var _loc_2:* = new Message(this._gameServerData);
            _loc_2.injectParams();
            var _loc_3:* = new CallbackRequest(param1);
            this.request(CGSServerConstants.LOAD_USER_GAME_DATA, this.handleGameDataLoaded, _loc_2.messageObject, null, _loc_3);
            return;
        }// end function

        private function handleGameDataLoaded(param1:String, param2:Boolean, param3:CallbackRequest) : void
        {
            var _loc_6:Object = null;
            var _loc_7:UserGameDataRequest = null;
            var _loc_4:* = param3.callback;
            var _loc_5:UserGameData = null;
            if (!param2)
            {
                _loc_6 = this.parseResponseData(param1);
                _loc_7 = new UserGameDataRequest();
                _loc_7.data = _loc_6;
                _loc_5 = _loc_7.userGameData;
            }
            if (_loc_4 != null)
            {
                this._loc_4(_loc_5, param2);
            }
            return;
        }// end function

        public function loadGameDataByID(param1:String, param2:Function) : void
        {
            var _loc_3:* = new Message(this._gameServerData);
            _loc_3.addProperty("udata_id", param1);
            _loc_3.injectParams();
            var _loc_4:* = new GameDataRequest(param2, param1);
            this.request(CGSServerConstants.LOAD_GAME_DATA, this.handleGameDataLoadByID, _loc_3.messageObject, null, _loc_4);
            return;
        }// end function

        private function handleGameDataLoadByID(param1:String, param2:Boolean, param3:GameDataRequest) : void
        {
            var _loc_6:Object = null;
            var _loc_7:UserDataChunkResponse = null;
            var _loc_4:* = param3.callback;
            var _loc_5:UserDataChunk = null;
            if (!param2)
            {
                _loc_6 = this.parseResponseData(param1);
                _loc_7 = new UserDataChunkResponse();
                _loc_7.data = _loc_6;
                _loc_5 = _loc_7.dataChunk;
            }
            if (_loc_4 != null)
            {
                this._loc_4(_loc_5, param2);
            }
            return;
        }// end function

        public function saveTOSStatus(param1:Boolean, param2:Function = null) : void
        {
            this.saveGameData(CGSServerConstants.TOS_DATA_ID, param1, param2);
            return;
        }// end function

        public function loadTOSStatus(param1:Function) : void
        {
            var _loc_2:* = new Message(this._gameServerData);
            _loc_2.addProperty("udata_id", CGSServerConstants.TOS_DATA_ID);
            _loc_2.injectParams();
            var _loc_3:* = new CallbackRequest(param1);
            this.request(CGSServerConstants.LOAD_GAME_DATA, this.handleGameDataLoadByID, _loc_2.messageObject, null, _loc_3);
            return;
        }// end function

        private function handleLoadTOSStatus(param1:String, param2:Boolean, param3:CallbackRequest) : void
        {
            var _loc_4:* = param3.callback;
            var _loc_5:Boolean = false;
            if (!param2)
            {
                _loc_5 = this.parseResponseData(param1);
                this._userAcceptedTOS = _loc_5;
            }
            if (_loc_4 != null)
            {
                this._loc_4(_loc_5, param2);
            }
            return;
        }// end function

        public function requestLoggingData(param1:String, param2:Object, param3:Function, param4:String = "TEXT") : void
        {
            var _loc_6:String = null;
            var _loc_7:CallbackRequest = null;
            var _loc_5:* = new Message(this._gameServerData);
            for (_loc_6 in param2)
            {
                
                _loc_5.addProperty(_loc_6, param2[_loc_6]);
            }
            _loc_5.injectParams();
            _loc_7 = new CallbackRequest(param3, param4);
            this.request(param1, this.handleLoggingDataLoaded, _loc_5.messageObject, null, _loc_7);
            return;
        }// end function

        private function handleLoggingDataLoaded(param1:String, param2:Boolean, param3:CallbackRequest) : void
        {
            var _loc_4:* = this.parseResponseData(param1, param3.returnDataType);
            var _loc_5:* = param3.callback;
            if (param3.callback != null)
            {
                this._loc_5(_loc_4, param2);
            }
            return;
        }// end function

        private function parseResponseData(param1:String, param2:String = "JSON")
        {
            var _loc_4:URLVariables = null;
            var _loc_5:String = null;
            var _loc_6:JSONDecoder = null;
            var _loc_7:String = null;
            var _loc_8:Object = null;
            var _loc_3:* = null;
            try
            {
                _loc_4 = new URLVariables(param1);
                _loc_5 = _loc_4.data;
                if (param2 == "JSON")
                {
                    _loc_6 = new JSONDecoder(_loc_5, true);
                    _loc_3 = _loc_6.getValue();
                }
                else
                {
                    _loc_3 = _loc_5;
                }
                if (_loc_4.hasOwnProperty("server_data"))
                {
                    _loc_7 = _loc_4.serverData;
                    _loc_6 = new JSONDecoder(_loc_7, true);
                    _loc_8 = _loc_6.getValue();
                    this.updateLoggingLoad(_loc_8);
                    if (_loc_8.hasOwnProperty("pvid"))
                    {
                        this._currentResponseVersion = _loc_8.pvid;
                    }
                    else
                    {
                        this._currentResponseVersion = 0;
                    }
                }
                else
                {
                    this._currentResponseVersion = 0;
                    if (param2 == "JSON")
                    {
                        this.updateLoggingLoad(_loc_3);
                    }
                }
            }
            catch (er:Error)
            {
            }
            return _loc_3;
        }// end function

        private function didRequestFail(param1:Object) : Boolean
        {
            if (param1 == null)
            {
                return true;
            }
            var _loc_2:Boolean = true;
            if (param1.hasOwnProperty("tstatus"))
            {
                _loc_2 = param1.tstatus != "t";
            }
            return _loc_2;
        }// end function

        public function onTick(param1:Number) : void
        {
            if (this._actionBufferHandler != null)
            {
                this._actionBufferHandler.onTick(param1);
            }
            return;
        }// end function

        public static function resetSingleton() : void
        {
            _instance = null;
            return;
        }// end function

        public static function failureLoggingEnabled(param1:Boolean) : void
        {
            instance._logFailuresEnabled = param1;
            return;
        }// end function

        public static function set logPriorityChangeCallback(param1:Function) : void
        {
            instance.logPriorityChangeCallback = param1;
            return;
        }// end function

        public static function disableLogging() : void
        {
            instance.disableLogging();
            return;
        }// end function

        public static function enableLogging() : void
        {
            instance.enableLogging();
            return;
        }// end function

        public static function set requireTermsOfService(param1:Boolean) : void
        {
            instance.requireTermsOfService = param1;
            return;
        }// end function

        public static function set termsServiceAccepted(param1:Boolean) : void
        {
            instance.termsServiceAccepted = param1;
            return;
        }// end function

        public static function get termsServiceAccepted() : Boolean
        {
            return instance._userAcceptedTOS;
        }// end function

        public static function set actionBufferHandlerClass(param1:Class) : void
        {
            instance.actionBufferHandlerClass = param1;
            return;
        }// end function

        public static function set serverRequestHandlerClass(param1:Class) : void
        {
            instance.serverRequestHandlerClass = param1;
            return;
        }// end function

        public static function set serverRequestHandler(param1:IServerRequestHandler) : void
        {
            instance.serverRequestHandler = param1;
            return;
        }// end function

        public static function init(param1:CGSServerProps, param2:Boolean = true) : void
        {
            instance.init(param1, param2);
            return;
        }// end function

        public static function get serverData() : GameServerData
        {
            return instance.serverData;
        }// end function

        public static function set skey(param1:String) : void
        {
            instance.skey = param1;
            return;
        }// end function

        public static function set skeyHashVersion(param1:int) : void
        {
            instance.skeyHashVersion = param1;
            return;
        }// end function

        public static function set gameName(param1:String) : void
        {
            instance.gameName = param1;
            return;
        }// end function

        public static function set gameID(param1:int) : void
        {
            instance.gameID = param1;
            return;
        }// end function

        public static function set questGameID(param1:int) : void
        {
            instance.questGameID = param1;
            return;
        }// end function

        public static function set versionID(param1:int) : void
        {
            instance.versionID = param1;
            return;
        }// end function

        public static function set catergoryID(param1:int) : void
        {
            instance.categoryID = param1;
            return;
        }// end function

        public static function set serverURL(param1:String) : void
        {
            instance.serverURL = param1;
            return;
        }// end function

        public static function set useDevelopmentServer(param1:Boolean) : void
        {
            instance.useDevelopmentServer = param1;
            return;
        }// end function

        public static function set abTestingURL(param1:String) : void
        {
            instance.abTestingURL = param1;
            return;
        }// end function

        public static function set legacyMode(param1:Boolean) : void
        {
            instance.legacyMode = param1;
            return;
        }// end function

        public static function get instance() : CGSServer
        {
            if (_instance == null)
            {
                _instance = new CGSServer;
            }
            return _instance;
        }// end function

        public static function setUserDomain(param1:Stage) : void
        {
            if (param1 == null)
            {
                return;
            }
            var _loc_2:* = param1.root.loaderInfo.url.split("/")[2];
            _loc_2 = _loc_2 == null ? ("") : (_loc_2);
            if (_loc_2.length == 0)
            {
                _loc_2 = "local";
            }
            instance._swfDomain = _loc_2;
            if (instance._gameServerData != null)
            {
                instance._gameServerData.swfDomain = _loc_2;
            }
            return;
        }// end function

        public static function genRequest(param1:String, param2:String, param3:Function = null, param4:Object = null, param5:Object = null, param6 = null, param7:Class = null, param8:String = "text") : void
        {
            instance.genRequest(param1, param2, param3, param4, param5, param6, param7, param8);
            return;
        }// end function

        public static function request(param1:String, param2:Function = null, param3:Object = null, param4:Object = null, param5 = null, param6:Class = null, param7:String = "text") : void
        {
            instance.request(param1, param2, param3, param4, param5, param6, param7);
            return;
        }// end function

        public static function abRequest(param1:String, param2:Function = null, param3:Object = null, param4:Object = null, param5 = null, param6:Class = null, param7:String = "TEXT") : void
        {
            instance.abRequest(param1, param2, param3, param4, param5, param6, param7);
            return;
        }// end function

        public static function requestUserTestConditions(param1:Function = null) : void
        {
            instance.requestUserTestConditions(param1);
            return;
        }// end function

        public static function noUserConditions() : void
        {
            instance.noUserConditions();
            return;
        }// end function

        public static function logTestStart(param1:int, param2:int, param3:Object = null, param4:Function = null) : void
        {
            instance.logTestStart(param1, param2, param3, param4);
            return;
        }// end function

        public static function logTestEnd(param1:int, param2:int, param3:Object = null, param4:Function = null) : void
        {
            instance.logTestEnd(param1, param2, param3, param4);
            return;
        }// end function

        public static function logConditionVariableStart(param1:int, param2:int, param3:int, param4:int, param5:Number = -1, param6:Object = null, param7:Function = null) : void
        {
            instance.logConditionVariableStart(param1, param2, param3, param4, param5, param6, param7);
            return;
        }// end function

        public static function logConditionVariableResults(param1:int, param2:int, param3:int, param4:int, param5:Number = -1, param6:Object = null, param7:Function = null) : void
        {
            instance.logConditionVariableResults(param1, param2, param3, param4, param5, param6, param7);
            return;
        }// end function

        public static function createUUIDForExternalID(param1:Function, param2:String) : void
        {
            return;
        }// end function

        public static function requestUUIDForExternalID(param1:Function, param2:String) : void
        {
            return;
        }// end function

        public static function requestUUID(param1:Function, param2:Boolean = false, param3:String = null) : void
        {
            instance.requestUUID(param1, param2, param3);
            return;
        }// end function

        public static function containsUUID() : Boolean
        {
            return instance.containsUUID();
        }// end function

        public static function clearCachedUUID() : void
        {
            instance.clearCachedUUID();
            return;
        }// end function

        public static function logActionNoQuest(param1:ActionNoQuestMessage, param2:Function = null) : void
        {
            instance.logActionNoQuest(param1);
            return;
        }// end function

        public static function logPageLoad(param1:Object = null, param2:Function = null) : void
        {
            instance.logPageLoad(param1);
            return;
        }// end function

        public static function submitUserFeedback(param1:UserFeedbackMessage, param2:Function = null) : void
        {
            instance.submitUserFeedback(param1, param2);
            return;
        }// end function

        public static function requestDQID(param1:Function, param2:int = -1) : void
        {
            instance.requestDQID(param1);
            return;
        }// end function

        public static function createQuest(param1:String, param2:int, param3:Function = null) : void
        {
            instance.createQuest(param1, param2, param3);
            return;
        }// end function

        public static function logQuestStartWithDQID(param1:int, param2:String, param3:Object, param4:String = null) : int
        {
            return instance.logQuestStartWithDQID(param1, param2, param3, param4);
        }// end function

        public static function logQuestStart(param1:int, param2:Object, param3:Function = null, param4:String = null, param5:int = -1) : int
        {
            return instance.logQuestStart(param1, param2, param3, param4, param5);
        }// end function

        public static function legacyLogQuestStart(param1:int, param2:Object, param3:Function = null, param4:String = null, param5:int = -1) : int
        {
            return instance.legacyLogQuestStart(param1, param2, param3, param4, param5);
        }// end function

        public static function logQuestEnd(param1:int, param2:Object, param3:Function = null, param4:int = -1) : void
        {
            instance.logQuestEnd(param1, param2, param3, param4);
            return;
        }// end function

        public static function logQuestAction(param1:ClientAction, param2:int = -1, param3:Boolean = false) : void
        {
            instance.logQuestAction(param1, param2, param3);
            return;
        }// end function

        public static function pauseActionBufferHandler() : void
        {
            instance.pauseActionBufferHandler();
            return;
        }// end function

        public static function resumeActionBufferHandler() : void
        {
            instance.resumeActionBufferHandler();
            return;
        }// end function

        public static function flushActions(param1:int = -1, param2:Function = null) : void
        {
            instance.flushActions(param1, param2);
            return;
        }// end function

        private static function flushActionsOptions(param1:Boolean, param2:int = -1, param3:Function = null) : void
        {
            instance.flushActionsOptions(param1, param2, param3);
            return;
        }// end function

        public static function logQuestScore(param1:Number, param2:Function = null, param3:int = -1) : void
        {
            instance.logQuestScore(param1, param2, param3);
            return;
        }// end function

        public static function logScore(param1:Number, param2:int, param3:Function = null) : void
        {
            instance.logScore(param1, param2, param3);
            return;
        }// end function

        public static function requestScoresByQuestID(param1:int) : void
        {
            instance.requestScores();
            return;
        }// end function

        public static function saveGameData(param1:String, param2, param3:Function = null) : void
        {
            instance.saveGameData(param1, param2, param3);
            return;
        }// end function

        public static function loadGameData(param1:Function) : void
        {
            instance.loadGameData(param1);
            return;
        }// end function

        public static function saveTOSStatus(param1:Boolean, param2:Function = null) : void
        {
            instance.saveTOSStatus(param1, param2);
            return;
        }// end function

        public static function loadTOSStatus(param1:Function) : void
        {
            instance.loadTOSStatus(param1);
            return;
        }// end function

        public static function requestLoggingData(param1:String, param2:Object, param3:Function, param4:String = "TEXT") : void
        {
            instance.requestLoggingData(param1, param2, param3, param4);
            return;
        }// end function

        public static function getTimeStamp() : String
        {
            var _loc_1:* = new Date().getTime();
            return _loc_1.toString(36);
        }// end function

    }
}
